package com.ht.project.action;

import java.util.UUID;

import javax.servlet.ServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ht.right.entity.ProamanageHeadModel;
import com.ht.right.service.CommonFacadeService;
import com.ht.right.util.CommonUtil;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class PromanageAction extends ActionSupport implements ModelDriven<ProamanageHeadModel> {
	private static final long serialVersionUID = -3875985983108176768L;
	private ProamanageHeadModel proamanageHeadModel;
	private CommonFacadeService<ProamanageHeadModel> commonFacadeService;
	private String uuid;
	
	
	//更具条件查找项目立项
	public String findPromanageById() {
		String uuid = ServletActionContext.getRequest().getParameter("uuid");
		proamanageHeadModel = commonFacadeService.getEntityByID("ProamanageHeadModel", uuid);
		CommonUtil.toJsonStr(ServletActionContext.getResponse(), proamanageHeadModel);
		return null;
	}

	
	//添加项目立项
	public String addPromanage(){
		ServletRequest request = ServletActionContext.getRequest();
		String rightId = request.getParameter("menuId");
		proamanageHeadModel.setUuid(UUID.randomUUID().toString());
		commonFacadeService.save(proamanageHeadModel, rightId);
		return "success";
	}
	
	//更新项目立项
	public String updatePromanage(){
		commonFacadeService.saveOrUpdate(proamanageHeadModel);
		return "success";
	}

	public ProamanageHeadModel getProamanageHeadModel() {
		return proamanageHeadModel;
	}

	public void setProamanageHeadModel(ProamanageHeadModel proamanageHeadModel) {
		this.proamanageHeadModel = proamanageHeadModel;
	}

	@Override
	public ProamanageHeadModel getModel() {
		if(CommonUtil.isNullOrEmpty(proamanageHeadModel)){
			proamanageHeadModel = new ProamanageHeadModel();
		}
		return proamanageHeadModel;
	}

	public CommonFacadeService<ProamanageHeadModel> getCommonFacadeService() {
		return commonFacadeService;
	}

	public void setCommonFacadeService(
			CommonFacadeService<ProamanageHeadModel> commonFacadeService) {
		this.commonFacadeService = commonFacadeService;
	}
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}
	
}
